using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//类似于监听者模式，从这个Manager接口找到所有的管理器，调用其方法
public class Manager : MonoBehaviour
{
    //私有静态字段（通常用于实现单例模式），static保证全局唯一，所有实例共享这一个字段
    private static ResourceManager _resource;
    private static LuaManager _lua;
    private static UIManager _ui;
    private static EntityManager _entity;
    private static MySceneManager _scene;
    private static SoundManager _sound;
    private static EventManager _event;
    private static PoolManager _pool;
    private static NetManager _net;
    //对私有静态字段进行封装，对外提供访问接口
    public static ResourceManager Resource
    {
        get { return _resource; }   
    }    
    public static LuaManager Lua
    {
        get { return _lua; }   
    }
    public static UIManager UI
    {
        get { return _ui; }
    }
    public static EntityManager Entity
    {
        get { return _entity; }
    }
    public static MySceneManager Scene
    {
        get { return _scene; }
    }
    public static SoundManager Sound
    {
        get { return _sound; }
    }
    public static EventManager Event
    {
        get { return _event; }
    }
    public static PoolManager Pool
    {
        get { return _pool; }
    }
    public static NetManager Net
    {
        get { return _net; }
    }


    public void Awake()
    {
        //对管理器字段进行实例化，添加到管理器对象上，执行生命周期函数
        //管理器对象为root的子物件，保证不会因为切换场景而销毁
        _resource = this.gameObject.AddComponent<ResourceManager>();
        _lua = this.gameObject.AddComponent<LuaManager>();
        _ui = this.gameObject.AddComponent<UIManager>();
        _entity = this.gameObject.AddComponent<EntityManager>();
        _scene = this.gameObject.AddComponent<MySceneManager>();
        _sound = this.gameObject.AddComponent<SoundManager>();
        _event = this.gameObject.AddComponent<EventManager>();
        _pool = this.gameObject.AddComponent<PoolManager>();
        _net = this.gameObject.AddComponent<NetManager>();
    }
}
